package eleanor.ltd.isRealEstate.pages;

import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.Request;

import eleanor.ltd.isRealEstate.annotations.BuyerAccess;
import eleanor.ltd.isRealEstate.security.AuthenticationException;
import eleanor.ltd.isRealEstate.services.Authenticator;

@BuyerAccess
public class Login {

	@Property
    private String username;

    @Property
    private String password;

    @Inject
    private Authenticator authenticator;
    
    @Component
    private Form loginForm;
    
    @Log
    Object onSubmitFromLoginForm() {
    	try {
            	System.out.println("Provjera");
            	authenticator.login(username, password);
            	System.out.println("Uspjesno");
                return Index.class;
            } catch (AuthenticationException ex) {
//            	errorPage.setMessage("Wrong username/password, please try again!");
                return Login.class;
            }
    }

}
